/**
 * * Copyright &copy; 2015-2020 <a href="https://gitee.com/JeeHuangBingGui/JeeSpring">JeeSpring</a> All rights reserved..
 */
package com.jeespring.modules.sys.service;

import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jeespring.common.service.TreeService;
import com.jeespring.modules.sys.dao.OfficeDao;
import com.jeespring.modules.sys.entity.Office;
import com.jeespring.modules.sys.utils.UserUtils;

/**
 * 机构Service
 * 
 * @author 黄炳桂 516821420@qq.com
 * @version 2014-05-16
 */
@Service
@Transactional(readOnly = true)
public class OfficeService extends TreeService<OfficeDao, Office> {

    public List<Office> findAll() {
        return UserUtils.getOfficeList();
    }

    public List<Office> findList(Boolean isAll) {
        if (isAll != null && isAll) {
            return UserUtils.getOfficeAllList();
        } else {
            return UserUtils.getOfficeList();
        }
    }

    @Override
    @Transactional(readOnly = true)
    public List<Office> findList(Office office) {
        office.setParentIds(office.getParentIds() + "%");
        return dao.findByParentIdsLike(office);
    }

    @Transactional(readOnly = true)
    public Office getByCode(String code) {
        return dao.getByCode(code);
    }

    @Override
    @Transactional(readOnly = false)
    public void save(Office office) {
        super.save(office);
        UserUtils.removeCache(UserUtils.CACHE_OFFICE_LIST);
    }

    @Override
    @Transactional(readOnly = false)
    public void delete(Office office) {
        super.deleteByLogic(office);
        UserUtils.removeCache(UserUtils.CACHE_OFFICE_LIST);
    }

}
